<?php
namespace Admin\Controller;

use Think\Controller;

class  PositioncontentController extends Controller
{
    public function index()
    {
        $positions = D("Position")->getNormalPositions();
        //获取推荐位里的内容
        $data['status'] = ['neq' , -1];
        if (trim(I('title'))){
            $data['title'] = trim(I('title'));
            $this->assign('title' , $data['title']);
        }
        //这里的查询有点不太友好
        $data['position_id'] = I('position_id') ? intval(I('position_id')) : 0;
        $this->assign('contens' , D('PositionContent')->select($data));
        $this->assign('positions' , $positions);
        $this->assign('positionId' , $data['position_id']);
        $this->display();
    }

    public function setStatus($id , $status) {
        if (IS_POST){
            $data['id'] = $id;
            $data['status'] = $status;
            $url = $_SERVER['HTTP_REFERER'];
            $positionId = D('PositionContent')->save($data);
            if ($positionId){
                return show(1 , '修改成功');
            }else{
                return show(0, '修改失败' , $url);
            }
        }
    }
}